//
//  RegisterController.swift
//  ExpressDriver
//
//  Created by sheng on 2017/11/22.
//  Copyright © 2017年 sheng. All rights reserved.
//

import UIKit
import SnapKit

class RegisterController: UIViewController {
    
    var userNameEdt: UITextField!
    
    var passwordEdt: UITextField!
    
    var confirmPasswordEdt: UITextField!
    
    var emailEdt: UITextField!
    
    var phoneNumberEdt: UITextField!
    
    var companyIdEdt: UITextField!
    
    var messageBtn: UIButton!
    
    var phoneBtn: UIButton!
    
    var validationEdt: UITextField!
    
    var registerBtn: UIButton!
    

    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
    }
    
    
    func setUI() {
        
        self.view.backgroundColor = UIColor.white
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "cancel", style: .plain, target: self, action: #selector(cancelButtonClick))
        
        let userImg =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        userImg.image = UIImage(named:"user")
        userNameEdt = UITextField()
        userNameEdt.placeholder="Username"
        userNameEdt.font = UIFont.systemFont(ofSize: 14)
        userNameEdt.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        userNameEdt.leftViewMode = UITextFieldViewMode.always
        userNameEdt.leftView!.addSubview(userImg)
        userNameEdt.borderStyle = UITextBorderStyle.roundedRect
        self.view.addSubview(userNameEdt)
        userNameEdt.snp.makeConstraints { (make) in
            make.top.equalTo(self.view.snp.top).offset(79)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(40)
        }
        
        
        let passwordImg =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        passwordImg.image = UIImage(named:"password")
        passwordEdt = UITextField()
        passwordEdt.placeholder="Password"
        passwordEdt.font = UIFont.systemFont(ofSize: 14)
        passwordEdt.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        passwordEdt.leftViewMode = UITextFieldViewMode.always
        passwordEdt.leftView!.addSubview(passwordImg)
        passwordEdt.borderStyle = UITextBorderStyle.roundedRect
        self.view.addSubview(passwordEdt)
        passwordEdt.snp.makeConstraints { (make) in
            make.top.equalTo(userNameEdt.snp.bottom).offset(10)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(40)
        }
        
        let confirmImg =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        confirmImg.image = UIImage(named:"password")
        confirmPasswordEdt = UITextField()
        confirmPasswordEdt.placeholder="Confirm Password"
        confirmPasswordEdt.font = UIFont.systemFont(ofSize: 14)
        confirmPasswordEdt.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        confirmPasswordEdt.leftViewMode = UITextFieldViewMode.always
        confirmPasswordEdt.leftView!.addSubview(confirmImg)
        confirmPasswordEdt.borderStyle = UITextBorderStyle.roundedRect
        self.view.addSubview(confirmPasswordEdt)
        confirmPasswordEdt.snp.makeConstraints { (make) in
            make.top.equalTo(passwordEdt.snp.bottom).offset(10)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(40)
        }
        
        
        let emailImg =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        emailImg.image = UIImage(named:"email")
        emailEdt = UITextField()
        emailEdt.placeholder="Email"
        emailEdt.font = UIFont.systemFont(ofSize: 14)
        emailEdt.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        emailEdt.leftViewMode = UITextFieldViewMode.always
        emailEdt.leftView!.addSubview(emailImg)
        emailEdt.borderStyle = UITextBorderStyle.roundedRect
        self.view.addSubview(emailEdt)
        emailEdt.snp.makeConstraints { (make) in
            make.top.equalTo(confirmPasswordEdt.snp.bottom).offset(10)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(40)
        }
        
        
        let phoneImg =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        phoneImg.image = UIImage(named:"phone")
        phoneNumberEdt = UITextField()
        phoneNumberEdt.placeholder="Mobile Number"
        phoneNumberEdt.font = UIFont.systemFont(ofSize: 14)
        phoneNumberEdt.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        phoneNumberEdt.leftViewMode = UITextFieldViewMode.always
        phoneNumberEdt.leftView!.addSubview(phoneImg)
        phoneNumberEdt.borderStyle = UITextBorderStyle.roundedRect
        self.view.addSubview(phoneNumberEdt)
        phoneNumberEdt.snp.makeConstraints { (make) in
            make.top.equalTo(emailEdt.snp.bottom).offset(10)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(40)
        }
        

        let companyImg =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        companyImg.image = UIImage(named:"company")
        companyIdEdt = UITextField()
        companyIdEdt.placeholder="Company ID"
        companyIdEdt.font = UIFont.systemFont(ofSize: 14)
        companyIdEdt.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        companyIdEdt.leftViewMode = UITextFieldViewMode.always
        companyIdEdt.leftView!.addSubview(companyImg)
        companyIdEdt.borderStyle = UITextBorderStyle.roundedRect
        self.view.addSubview(companyIdEdt)
        companyIdEdt.snp.makeConstraints { (make) in
            make.top.equalTo(phoneNumberEdt.snp.bottom).offset(10)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(40)
        }
        
        
        let messageLabel: UILabel = UILabel()
        messageLabel.font = UIFont.systemFont(ofSize: 12)
        messageLabel.numberOfLines = 0
        messageLabel.textAlignment = .center
        let attributeString = NSMutableAttributedString(string:"Active By\r\nOr")
        attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.red,
                                     range: NSMakeRange(0, 9))
        messageLabel.attributedText = attributeString
        self.view.addSubview(messageLabel)
        messageLabel.snp.makeConstraints { (make) in
            make.top.equalTo(companyIdEdt.snp.bottom).offset(10)
            make.centerX.equalTo(self.view)
        }

        
        messageBtn = UIButton()
        let messgeImage = UIImage(named:"message_icon")?.withRenderingMode(.alwaysOriginal)
        messageBtn.setImage(messgeImage, for:.normal)
        messageBtn.adjustsImageWhenHighlighted = false
        self.view.addSubview(messageBtn)
        messageBtn.snp.makeConstraints { (make) in
            make.right.equalTo(messageLabel.snp.left).offset(-10)
            make.centerY.equalTo(messageLabel)
            make.width.height.equalTo(35)
        }
        
        
        phoneBtn = UIButton()
        let mobileImage = UIImage(named:"mobile")?.withRenderingMode(.alwaysOriginal)
        phoneBtn.setImage(mobileImage, for:.normal)
        phoneBtn.adjustsImageWhenHighlighted = false
        self.view.addSubview(phoneBtn)
        phoneBtn.snp.makeConstraints { (make) in
            make.left.equalTo(messageLabel.snp.right).offset(10)
            make.centerY.equalTo(messageLabel)
            make.width.height.equalTo(25)
        }
        
        
        let validationImg =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        validationImg.image = UIImage(named:"validation")
        validationEdt = UITextField()
        validationEdt.placeholder="Validation Code"
        validationEdt.font = UIFont.systemFont(ofSize: 14)
        validationEdt.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        validationEdt.leftViewMode = UITextFieldViewMode.always
        validationEdt.leftView!.addSubview(validationImg)
        validationEdt.borderStyle = UITextBorderStyle.roundedRect
        self.view.addSubview(validationEdt)
        validationEdt.snp.makeConstraints { (make) in
            make.top.equalTo(messageLabel.snp.bottom).offset(10)
            make.left.equalTo(15)
            make.right.equalTo(-15)
            make.height.equalTo(40)
        }
        
        
        registerBtn = UIButton()
        registerBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        registerBtn.setTitle("Determine", for: UIControlState())
        registerBtn.setTitleColor(UIColor.black, for: UIControlState())
        registerBtn.layer.borderColor = UIColor.lightGray.cgColor
        registerBtn.layer.borderWidth = 0.5
        registerBtn.layer.cornerRadius = 5
        self.view.addSubview(registerBtn)
        registerBtn.snp.makeConstraints { (make) in
            make.top.equalTo(validationEdt.snp.bottom).offset(15)
            make.centerX.equalTo(self.view)
            make.width.equalTo(200)
            make.height.equalTo(40)
        }
        
    }
    
    
    
    func cancelButtonClick() {
        dismiss(animated: true, completion: nil)
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
